// 购物车的渲染
$(function () {
  window.onload = function () {
    $.ajax({
      url: "http://localhost:3000/api/list/goods",
      success: (res) => {
        res = JSON.parse(res);
        proMsg = localStorage.getItem("proMsg")
          ? JSON.parse(localStorage.getItem("proMsg"))
          : [];
        // console.log(proMsg);
        let str = "";
        for (let i = 0; i < res.length; i++) {
          for (let j = 0; j < proMsg.length; j++) {
            if (res[i].id === proMsg[j].id) {
              str += `
                            <tr>
                                <td class="checkbox">
                                    <input class="check-one check" type="checkbox" />
                                </td>
                                <td class="goods">
                                    <img src="${res[i].src1}" alt="" />
                                    <span>${res[i].name}</span>
                                </td>
                                <td class="price">${res[i].pricep}</td>
                                <td class="count">
                                    <span class="reduce"></span>
                                    <input class="count-input" type="text" value="${this.proMsg[j].num}" />
                                    <span class="add">+</span>
                                </td>
                                <td class="subtotal">${res[i].pricep}</td>
                                <td class="operation"><span class="delete">删除</span></td>
                            </tr>
                            `;
            }
          }
        }
        $(".cart-main").html(str);
        aa(); //购物车的内容操作方法
      },
    });
  };
});
